package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import metier.AquariumTechniqueException;


public class SimpleConnection {
		
		
		private static SimpleConnection sc;	
		private SimpleConnection (){}	
		public static SimpleConnection getInstance(){
			if(sc==null) {
				sc = new SimpleConnection();
			}
			return sc;	
		}
		
		
	public Connection getConnection() throws AquariumTechniqueException {
		Connection maConnection = null ;
		
		//ChargeProperty p = null ;
		//p.getInstance();
		
		final String driver="sun.jdbc.odbc.JdbcOdbcDriver";
		final String URL = "jdbc:odbc:aquarium" ;
		
		//final String driver = p.getPropriete(driver);
		//final String URL = p.getPropriete(url) ;
		
		try
		{
			Class.forName(driver);
			maConnection=DriverManager.getConnection(URL);
		}
		catch(ClassNotFoundException cnf)
		{
			throw new AquariumTechniqueException("Erreur CNF");
			
		}
		catch(SQLException se)
		{
			se.printStackTrace();
			throw new AquariumTechniqueException("Erreur SQL !");
		}
		return maConnection ;
	}
		
		
	public static void main(String[] args) {
		Connection col = null ;
		try {
			col = SimpleConnection.getInstance().getConnection();
		} catch (AquariumTechniqueException e) {
			e.printStackTrace() ;
		}
		System.out.println("-->Simple Connection : "+col.toString()) ;
	}
}
